import store from "../store";


export function checkLogin(backUrl) {
  var token = store.state?.vuex_user?.token || ""
  if(!token){
	if(!backUrl){
		 // 获取当前页面的路径
		 const pages = getCurrentPages();
		 const currentPage = pages[pages.length - 1];
		 const currentPath = currentPage.route; // 不带查询参数的路径
		 const backUrl = currentPage.route + (currentPage.$options?.query ? '?' + JSON.stringify(currentPage.$options.query) : ''); // 包含查询参数的完整路径
		  console.log('/pages/public/login?backUrl='+encodeURIComponent(backUrl))
	}
	
	uni.navigateTo({
	  url: '/pages/public/login?backUrl='+encodeURIComponent(backUrl)
	})
  }
  
  return true;
}